package com.fdb.efp.nls.service.impl;

import com.fdb.basic.framework.core.base.FrameworkService;
import com.fdb.efp.nls.service.dao.BdAccLedgerDetailInfoDao;
import com.fdb.efp.nls.service.domain.BdAccLedgerDetailInfo;
import com.fdb.efp.nls.service.facade.BdAccLedgerDetailInfoService;
import com.fdb.efp.nls.service.vo.BdAccLedgerDetailInfoVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

/**
 * <p>ServiceImpl: 百度并账表				<p>
 * @author ligm
 * @date 2019-03-07
 */
@Service("bdAccLedgerDetailInfoService")
public class BdAccLedgerDetailInfoServiceImpl implements BdAccLedgerDetailInfoService, FrameworkService {
	
	private static Logger logger = LoggerFactory.getLogger(BdAccLedgerDetailInfoServiceImpl.class);

	@Autowired
	private BdAccLedgerDetailInfoDao bdAccLedgerDetailInfoDao;
	
	/**
	 * 新增操作
	 */
	public int insertBdAccLedgerDetailInfo(BdAccLedgerDetailInfoVO inBdAccLedgerDetailInfoVo) {
		logger.debug("当前新增数据为:"+ inBdAccLedgerDetailInfoVo.toString());
		int num = 0;
		try {
			BdAccLedgerDetailInfo bdAccLedgerDetailInfo = new BdAccLedgerDetailInfo();
			beanCopy(inBdAccLedgerDetailInfoVo, bdAccLedgerDetailInfo);
			num = bdAccLedgerDetailInfoDao.insertBdAccLedgerDetailInfo(bdAccLedgerDetailInfo);
		} catch (Exception e) {
			logger.error("新增数据发生异常!", e);
			num = -1;
		}
		logger.debug("当前新增数据条数为:"+ num);
		return num;
	}

	/**
	 * 删除操作
	 */
	public int deleteByPk(BdAccLedgerDetailInfoVO inBdAccLedgerDetailInfoVo) {
		logger.debug("当前删除数据条件为:"+ inBdAccLedgerDetailInfoVo);
		int num = 0;
		try {
			BdAccLedgerDetailInfo bdAccLedgerDetailInfo = new BdAccLedgerDetailInfo();
			beanCopy(inBdAccLedgerDetailInfoVo, bdAccLedgerDetailInfo);
			num = bdAccLedgerDetailInfoDao.deleteByPk(bdAccLedgerDetailInfo);
		} catch (Exception e) {
			logger.error("删除数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:"+ inBdAccLedgerDetailInfoVo +"删除的数据条数为"+ num);
		return num;
	}


	/**
	 * 更新操作
	 */
	public int updateByPk(BdAccLedgerDetailInfoVO inBdAccLedgerDetailInfoVo) {
		logger.debug("当前修改数据为:"+ inBdAccLedgerDetailInfoVo.toString());
		int num = 0;
		try {
			BdAccLedgerDetailInfo bdAccLedgerDetailInfo = new BdAccLedgerDetailInfo();
			beanCopy(inBdAccLedgerDetailInfoVo, bdAccLedgerDetailInfo);
			num = bdAccLedgerDetailInfoDao.updateByPk(bdAccLedgerDetailInfo);
		} catch (Exception e) {
			logger.error("修改数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:"+ inBdAccLedgerDetailInfoVo +"修改的数据条数为"+ num);
		return num;
	}
	
	/**
	 * 查询操作
	 */
	public BdAccLedgerDetailInfoVO queryByPk(BdAccLedgerDetailInfoVO inBdAccLedgerDetailInfoVo) {
		
		logger.debug("当前查询参数信息为:"+ inBdAccLedgerDetailInfoVo);
		try {
			BdAccLedgerDetailInfo queryBdAccLedgerDetailInfo = new BdAccLedgerDetailInfo();
			beanCopy(inBdAccLedgerDetailInfoVo, queryBdAccLedgerDetailInfo);
			BdAccLedgerDetailInfo queryRslBdAccLedgerDetailInfo = bdAccLedgerDetailInfoDao.queryByPk(queryBdAccLedgerDetailInfo);
			if (Objects.nonNull(queryRslBdAccLedgerDetailInfo)) {
				BdAccLedgerDetailInfoVO outBdAccLedgerDetailInfoVo = beanCopy(queryRslBdAccLedgerDetailInfo, new BdAccLedgerDetailInfoVO());
				logger.debug("当前查询结果为:"+ outBdAccLedgerDetailInfoVo.toString());
				return outBdAccLedgerDetailInfoVo;
			} else {
				logger.debug("当前查询结果为空!");
			}
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
		}
		return null;
	}


	/**
	 * 查询用户权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<BdAccLedgerDetailInfoVO> queryAllOwner(BdAccLedgerDetailInfoVO bdAccLedgerDetailInfoVo) {

		logger.debug("当前查询本人所属数据信息的参数信息为:");
		List<BdAccLedgerDetailInfoVO> list = null;
		try {
			List<BdAccLedgerDetailInfo> bdAccLedgerDetailInfos = bdAccLedgerDetailInfoDao.queryAllOwnerByPage(bdAccLedgerDetailInfoVo);
			logger.debug("当前查询本人所属数据信息的结果集数量为:"+ bdAccLedgerDetailInfos.size());
			pageSet(bdAccLedgerDetailInfos, bdAccLedgerDetailInfoVo);
			list = (List<BdAccLedgerDetailInfoVO>) beansCopy(bdAccLedgerDetailInfos, BdAccLedgerDetailInfoVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}


	/**
	 * 查询当前机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<BdAccLedgerDetailInfoVO> queryAllCurrOrg(BdAccLedgerDetailInfoVO bdAccLedgerDetailInfoVo) {

		logger.debug("当前查询本人所属机构数据信息的参数信息为:");
		List<BdAccLedgerDetailInfo> bdAccLedgerDetailInfos = bdAccLedgerDetailInfoDao.queryAllCurrOrgByPage(bdAccLedgerDetailInfoVo);
		logger.debug("当前查询本人所属机构数据信息的结果集数量为:"+bdAccLedgerDetailInfos.size());
		List<BdAccLedgerDetailInfoVO> list = null;
		try {
			pageSet(bdAccLedgerDetailInfos, bdAccLedgerDetailInfoVo);
			list = (List<BdAccLedgerDetailInfoVO>) beansCopy(bdAccLedgerDetailInfos, BdAccLedgerDetailInfoVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}


	/**
	 * 查询当前机构及下属机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<BdAccLedgerDetailInfoVO> queryAllCurrDownOrg(BdAccLedgerDetailInfoVO bdAccLedgerDetailInfoVo) {

		logger.debug("当前查询本人所属机构及以下数据信息的参数信息为:");
		List<BdAccLedgerDetailInfo> bdAccLedgerDetailInfos = bdAccLedgerDetailInfoDao.queryAllCurrDownOrgByPage(bdAccLedgerDetailInfoVo);
		logger.debug("当前查询本人所属机构及以下数据信息的结果集数量为:"+ bdAccLedgerDetailInfos.size());
		List<BdAccLedgerDetailInfoVO> list = null;
		try {
			pageSet(bdAccLedgerDetailInfos, bdAccLedgerDetailInfoVo);
			list = (List<BdAccLedgerDetailInfoVO>) beansCopy(bdAccLedgerDetailInfos, BdAccLedgerDetailInfoVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}
}
